import 'package:flutter/material.dart';
import 'package:shining_red_star/model/some_thing.dart';

import '../definitions/color.dart';
import 'focus_manage/focus_widget.dart';

class SomeThingIndexCard extends StatefulWidget {
  final SomeThingInfo someThing;
  final FocusNode focusNode;
  final bool? autofocus;
  final void Function()? onConfirm;

  SomeThingIndexCard({
    super.key,
    required this.someThing,
    this.autofocus,
    this.onConfirm,
    FocusNode? focusNode,
  }) : focusNode = focusNode ?? FocusNode();

  @override
  State<SomeThingIndexCard> createState() => _SomeThingIndexCardState();
}

class _SomeThingIndexCardState extends State<SomeThingIndexCard> {
  @override
  Widget build(BuildContext context) {
    bool showFocusStatus = widget.focusNode.hasFocus;
    return FocusWidget(
        focusNode: widget.focusNode,
        autofocus: widget.autofocus,
        onConfirm: widget.onConfirm,
        onFocusChange: (bool value) {
          setState(() {});
        },
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
                margin: EdgeInsets.only(bottom: 8),
                child: AspectRatio(
                  aspectRatio: 1,
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(16),
                    ),
                    clipBehavior: Clip.antiAlias,
                    child: Image(
                      image: AssetImage(
                          widget.someThing.img[0].replaceFirst('/', '')),
                      fit: BoxFit.cover,
                    ),
                  ),
                )),
            Text(
              widget.someThing.title,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                  fontSize: 14,
                  color: showFocusStatus ? SchemeColor.seedColor.value : null,
                  fontWeight: showFocusStatus ? FontWeight.bold : null),
            ),
          ],
        ));
  }
}
